import {defineStore} from "pinia";
import {
    addAuthInfo,
    cancelOrder,
    getAuthFlag,
    getOrderInfo, getOrderList,
    getOrderStatus,
    getPatientInfo,
    getPayStatus,
    qrCodeWx
} from "@/api/order";

interface useOrderType {
    orderInfo: any,
    cancelStatus: any,
    qrCode: any,
    userInfo: any,
    patient: any,
    orderStatus: any
    orderList: any,
    total: any
}

const useOrderStore = defineStore("order", {
    state: (): useOrderType => ({
        orderInfo: {},
        cancelStatus: {},
        qrCode: {},
        userInfo: {},
        patient: [],
        orderStatus: [],
        orderList: [],
        total: ""
    }),
    actions: {
        async getOrderInfoData(orderId: string) {
            const res = await getOrderInfo(orderId)
            this.orderInfo = res.data
        },
        async cancelOrderData(orderId: string) {
            const res = await cancelOrder(orderId)
            this.cancelStatus = res.data
        },
        async qrCodeWxData(orderId: string) {
            const res = await qrCodeWx(orderId)
            this.qrCode = res.data
        },
        async getAuthFlagData() {
            const res = await getAuthFlag()
            this.userInfo = res.data
        },
        async addAuthInfo(userParam: any) {
            await addAuthInfo(userParam)
        },
        async getPatientData() {
            const res = await getPatientInfo()
            this.patient = res.data
        },
        async getOrderStatusData() {
            const res = await getOrderStatus()
            this.orderStatus = res.data
        },
        async getOrderListData(page: number, limit: number, patientId = "", orderStatus = "") {
            const res = await getOrderList(page, limit, patientId, orderStatus)
            this.orderList = res.data
            this.total = res.data.total
        },
    }
});

export default useOrderStore
